package org.clienttest;

public class QuickSort {

	
	public static void quickSort(int[] arr , int left , int right){
		
		int low = left;
		int high = right;
		int key = arr[left];
		
		while( low<high ){
			while( low<high && arr[high]>key){
				high--;
			}
			if(low<high){
				int tmp = arr[high];
				arr[high] = arr[low];
				arr[low] = tmp;
				low++;
			}
			
			while( low<high && arr[low] < key){
				low++;
			}
			if(low<high){
				int tmp = arr[high];
				arr[high] = arr[low];
				arr[low] = tmp;
				high--;
			}
		}
		
//		for(int a :arr){
//			 System.out.print(a +" , ");
//		}
//		System.out.println("------------------");
		
		if(low > left){
			quickSort(arr , left , low-1);
		}
		if(high < right ){
			quickSort(arr , low+1 , right);
		}

	}
	
	
	public static void quickSort2(int [] arr ){
		
	}
	
	public static void main(String[] args) {
		
		int[ ] arr = new int[]{9,5,4,11,5,66,44};
		
		quickSort(arr , 0 , arr.length-1);
		
		for(int a :arr){
			 System.out.print(a +" , ");
		}
	}
	
}
